/*  PrimeBlaster
    by Kjetil Eide 
    kjetile445@gmail.com

    This file is part of PrimeBlaster

    PrimeBlaster is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    PrimeBlaster is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PrimeBlaster.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.eide.spaceship;

public class PlayerStatus {	
	public static final int MAX_LEVEL = 13;
	private int level;
	private int failedNumber;
	private boolean isDead;
	private boolean levelFinished;	
	
	public PlayerStatus() {
		reset();
		level = 0;
	}
	
	/**
	 * Get the number of asteroids that should
	 * appear on current level
	 * @return
	 */
	
	public int getNumberOfAsteroids() {
		int number = 2;
		
		if(level > 2)
			number = 3;
		
		if(level > 4)
			number = 4;
		
		return number;
	}
	
	public void setLevel(int level) {
		this.level = level;
		failedNumber = 0;
		isDead = false;
		levelFinished = false;
	}
	
	/* Evaluate the remaining asteroids and determine if
	 * player won or lost 
	 */
	public void evaluatePlayer(RBCollection rbCol) { 
		//System.out.println("Evaluating:");
		levelFinished = true;
		int idx = RBCollection.SHIP + 1;
			
		while(idx < rbCol.getNumberOfRB()) {
			Asteroid currentAsteroid = (Asteroid) (rbCol.getRB(idx));
			if (!PrimeNumbers.isPrime(currentAsteroid.getDisplayNumber())) {
				//System.out.println("Asteroid " + currentAsteroid.getDisplayNumber() + " is not prime");
				if (!isDead) {
					levelFinished = false;
					//System.out.println("You failed!!!");
					//setDead(true);
					//rbCol.blowShip();
				}
			} else {
				//System.out.println("Asteroid " + currentAsteroid.getDisplayNumber() + " is prime");
				//rbCol.blowAsteroid((Asteroid) rbCol.getRB(idx));
			}
			idx++;
		}
	}
	
	public int getLevel() {
		return level;
	}
	
	public int getFailedNumber() {
		return failedNumber;
	}
	
	public boolean isDead() {
		return isDead;
	}
	
	public boolean levelFinished() {
		return levelFinished;
	}
	
	public void increaseLevel() {
		level++;
		setLevel(level);
	}
	public void reset() {
		setFailedNumber(0);
		setlevelFinished(false);
		setDead(false);
	}
	public void setFailedNumber(int failedNumber) {
		this.failedNumber = failedNumber;
	}

	public void setDead(boolean isDead) {
		this.isDead = isDead;
	}
	
	public void setlevelFinished(boolean finished) {
		this.levelFinished = finished;
	}	
}
